//
// Created by dgy on 2022/11/9.
//

#include "queue"
#include "iostream"
using namespace std;
#include "vector"
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        vector<vector<int>> b;
        if (root==NULL)
            return b;
        queue<TreeNode*> queue;
        queue.push(root); 

        while (!queue.empty()){
            vector<int> tmp;
            int size=queue.size();
            for(;size--;queue.pop()){
                TreeNode* p=queue.front();
                if (p->left)
                    queue.push(p->left);
                if (p->right)
                    queue.push(p->right);
                tmp.push_back(p->val);
            }
            b.push_back(tmp);
        }
        return b;
    }
};
